package com.sgb.kjwl.view.ui.activity.pick;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPickExpertDetailsBinding;
import com.sgb.kjwl.view.ui.adapter.pick.PickAddViewAdapter;
import com.sgb.kjwl.view.ui.adapter.pick.PickExpertDetailsAdapter;
import com.sgb.kjwl.view.widget.pick.PickExpertDetailMajorView;
import com.sgb.kjwl.view.widget.pick.PickExpertDetailQualificationView;
import com.sgb.zhaocai.entity.PickExpertDetailEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 专家库详情页
 */
public class PickExpertDetailsActivity extends AppActivity {

    private ActivityPickExpertDetailsBinding binding;
    private PickExpertDetailEntity pickExpertDetailEntity;

    public static void start(Context context, PickExpertDetailEntity pickExpertDetailEntity) {
        Intent intent = new Intent();
        intent.setClass(context, PickExpertDetailsActivity.class);
        intent.putExtra("bean", pickExpertDetailEntity);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        pickExpertDetailEntity = (PickExpertDetailEntity) getIntent().getSerializableExtra("bean");
        binding = DataBindingUtil.setContentView(this, R.layout.activity_pick_expert_details);

        binding.topLayout.titleView.setText("专家详情页");
        binding.topLayout.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        binding.tvName.setText(pickExpertDetailEntity.getFullName());

        if (TextUtils.isEmpty(pickExpertDetailEntity.getGenderType())) {
            binding.imgGender.setVisibility(View.GONE);
        } else {
            binding.imgGender.setVisibility(View.VISIBLE);
            if ("01".equals(pickExpertDetailEntity.getGenderType())) {
                binding.imgGender.setBackgroundResource(R.drawable.man);
            } else if ("02".equals(pickExpertDetailEntity.getGenderType())) {
                binding.imgGender.setBackgroundResource(R.drawable.woman);
            } else {
                binding.imgGender.setVisibility(View.GONE);
            }
        }

        if (TextUtils.isEmpty(pickExpertDetailEntity.getProfessionName())) {
            binding.tvLevel.setVisibility(View.GONE);
        } else {
            binding.tvLevel.setVisibility(View.VISIBLE);
            binding.tvLevel.setText(pickExpertDetailEntity.getProfessionName());
        }

        if (TextUtils.isEmpty(pickExpertDetailEntity.getCategoryTypeName())) {
            binding.tvType.setVisibility(View.GONE);
        } else {
            binding.tvType.setVisibility(View.VISIBLE);
            binding.tvType.setText(pickExpertDetailEntity.getCategoryTypeName());
        }

        if (TextUtils.isEmpty(pickExpertDetailEntity.getUserName())) {
            binding.tvPhone.setVisibility(View.GONE);
        } else {
            binding.tvPhone.setVisibility(View.VISIBLE);
            binding.tvPhone.setText(pickExpertDetailEntity.getUserName());
        }

        PickExpertDetailsAdapter pickExpertDetailsAdapter = new PickExpertDetailsAdapter(getActivity(), pickExpertDetailEntity);
        binding.mainInfoRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.mainInfoRecycler.setAdapter(pickExpertDetailsAdapter);

        if (pickExpertDetailEntity.getMajors() != null && pickExpertDetailEntity.getMajors().size() > 0) {
            PickExpertDetailMajorView pickExpertDetailMajorView = new PickExpertDetailMajorView(getActivity());
            pickExpertDetailMajorView.showInfoView(pickExpertDetailEntity.getMajors());

            List<View> list = new ArrayList<>();
            list.add(pickExpertDetailMajorView);

            binding.majorsRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
            binding.majorsRecycler.setAdapter(new PickAddViewAdapter(getActivity(), list, R.layout.item_pick_add_child));
        } else {
            binding.majorsRecycler.setVisibility(View.GONE);
        }

        if (pickExpertDetailEntity.getQualifications() != null && pickExpertDetailEntity.getQualifications().size() > 0) {
            PickExpertDetailQualificationView pickExpertDetailQualificationView = new PickExpertDetailQualificationView(getActivity());
            pickExpertDetailQualificationView.showInfoView(pickExpertDetailEntity.getQualifications());

            List<View> list1 = new ArrayList<>();
            list1.add(pickExpertDetailQualificationView);

            binding.qualificationsRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
            binding.qualificationsRecycler.setAdapter(new PickAddViewAdapter(getActivity(), list1, R.layout.item_pick_add_child));
        } else {
            binding.qualificationsRecycler.setVisibility(View.GONE);
        }

    }

}

